﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class BaseData_AUTOPROP2 : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    private string tablename = "AUTOPROP2 A left join sxmx B on A.AP2_CODE=B.SXID and B.TableName='AUTOPROP2' left join SHUXING C on B.MXID=C.SX_ID";
    private string fieldname = "AP2_CODE, AP2_NAME, AP2_NOTE, AP2_FIELD1, AP2_FIELD2,SX_MC";
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200300105");
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());
            Model.FUNCTIONS func = new BLL.FUNCTIONS().GetModel("200300105");
            if (func != null)
            {
                lblPageTitle.Text = func.FUNC_NAME;
            }            
            SearchControl1.InitParam(tablename, fieldname, "AP2_CODE", "AP2_NAME", "AUTOPROP2ListControl1", "rptAUTOPROP2", "AspNetPager1");
            Bind();
            InitDanymic();
        }
    }
    private void Bind()
    {
        int pageCount, rowCount;
        List<Model.AUTOPROP2> properties = new BLL.AUTOPROP2().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, tablename, fieldname, "AP2_CODE", false, "", out pageCount, out rowCount);
        AUTOPROP2ListControl1.Bind(properties);
        AspNetPager1.RecordCount = rowCount;
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        int pageCount, rowCount;
        if (SearchControl1.IsSearchResult)
        {
            Repeater rpt = (Repeater)AUTOPROP2ListControl1.FindControl("rptAUTOPROP2");
            if (rpt != null)
            {
                string strSql;
                SearchControl1.BindParentPageControl(rpt, AspNetPager1, SearchControl1.DataTableName, SearchControl1.FieldName, SearchControl1.PrimaryKeyColumnName, SearchControl1.StrCondition, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out rowCount, out strSql);
            }
        }
        else
        {
            List<Model.AUTOPROP2> colors = new BLL.AUTOPROP2().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, tablename, fieldname, "AP2_CODE", false, "", out pageCount, out rowCount);
            AUTOPROP2ListControl1.Bind(colors);
        }
    }

    public void Add()
    {
        if (Check.CheckPermission("200300105", "00001"))
        {
            Response.Redirect("AUTOPROP2Edit.aspx");
        }
        else
        {
            Share.Alert(this.Page,"无权操作"); return;
        }
    }
    public void Update()
    {
        if (Check.CheckPermission("200300105", "00002"))
        {
            List<string> s = AUTOPROP2ListControl1.Selected;
            if (s.Count > 0)
            {
                Response.Redirect("AUTOPROP2Edit.aspx?code=" + s[0]);
            }
            else
            {
                //MessageBox.Show("s");
                Page.RegisterStartupScript("StartUp", "<script language=javascript>alert('请选择一条需要编辑的记录')</script>");
                //Share.Alert(this.Page,"请选择操作行"); 
            }
        }
        else
        {
            Share.Alert(this.Page,"无权操作"); return;
        }
    }
    public void Delete()
    {
        if (Check.CheckPermission("200300105", "00003"))
        {
            List<string> s = AUTOPROP2ListControl1.Selected;
            new BLL.AUTOPROP2().Delete(s);
            Share.InsertLog("200300105", "00003");
            Response.Redirect("AUTOPROP2.aspx");
        }
        else
        {
            Share.Alert(this.Page,"无权操作"); return;
        }
    }
    private void InitDanymic()
    {
        string flag = ConfigurationManager.AppSettings["DynamicProperty"].ToString();
        if (flag == "1")
        {
            UpdatePanel2.Visible = true;
            List<Model.SHUXING> l = new BLL.SHUXING().GetList("AUTOPROP2");
            SXMXControl1.Bind(l);
        }
        else
        {
            UpdatePanel2.Visible = false;
        }
    }
    public void AddProperty()
    {
        List<string> s = AUTOPROP2ListControl1.Selected;
        if (s.Count < 1)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('有选择记录');", true);
        }
        else
        {
            string sxid = SXMXControl1.SXID;
            string sxzcode = "";
            for (int i = 0; i < s.Count; i++)
            {
                sxzcode = sxzcode + s[i] + ",";
            }
            string table = "AUTOPROP2";
            bool f = new BLL.SXMX().Add(sxid, table, sxzcode);
            if (f)
            {
                Bind();
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('提交失败！');", true);
            }
        }
    }
}
